package noobteam.deartrainer.mapper;

import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * @author admin
 */
@Mapper
public interface TrainerInfoMapper {

    /**
     * 创建教练账号
     * 一般由管理员进行
     */
    @Insert("INSERT INTO trainersinfo (trainerName, trainerAge, trainerSex, trainerOnJobTime, trainerExperience, trainerPhone, trainerPassword) " +
            "VALUES (#{js.trainerName}, #{js.trainerAge}, #{js.trainerSex} , #{js.trainerOnJobTime} , #{js.trainerExperience}, #{js.trainerPhone}, #{js.trainerPassword})")
    public boolean insertTrainer(@Param("js") Map<String, String> map);

    /**
     * 教练查询账号信息
     */
    @Select("SELECT * FROM trainersinfo WHERE trainerId = #{trainerId}")
    public Map<String, Object> selectTrainMsgById(@Param("trainerId") Integer trainerId);

    /**
     * 通过电话查询用户信息
     */
    @Select("SELECT *\n" +
            "FROM trainersinfo\n" +
            "WHERE trainerPhone = #{trainerPhone}")
    public Map<String, Object> selectTrainMsgByPhone(@Param("trainerPhone") String trainerPhone);

    /**
     * 教练修改信息
     */
    @Update("UPDATE trainersinfo SET trainerName = #{js.trainerName}, " +
            "trainerAge = #{js.trainerAge}, trainerSex = #{js.trainerSex}, trainerPhilosophy = #{js.trainerPhilosophy} " +
            "WHERE trainerId = #{js.trainerId}")
    public boolean updateTrainerMsg(@Param("js") Map<String, String> map);

    /**
     * 教练查询旧密码
     * 用于教练修改密码时安全验证
     */
    @Select("SELECT trainerPassword FROM trainersinfo WHERE trainerId = #{trainerId}")
    public String getOldPassword(@Param("trainerId") Integer trainerId);

    /**
     * 教练修改密码
     */
    @Update("UPDATE trainersinfo SET trainerPassword = #{js.newPassword} " +
            "WHERE trainerId = #{js.trainerId}")
    public boolean updatePassword(@Param("js") Map<String,String> map);

    /**
     * 删除教练
     * 一般由管理员进行
     */
    @Delete("DELETE FROM trainersinfo WHERE trainerPhone = #{phone}")
    public boolean deleteTrainer(@Param("phone") String phone);

    /**
     * 注册时查询重复电话号码
     */
    @Select("SELECT trainerPhone FROM trainersinfo")
    public List<Map<String,Object>> selectTrainerPhone();

    /**
     * 获取教练列表
     * 返回所有教练的信息
     */
    @Select("SELECT * FROM trainersinfo")
    public List<Map<String, Object>> getTrainersList();

    /**
     * 获取教练列表
     * 将教练信息按照入职时间
     */
    @Select("SELECT * FROM trainersinfo ORDER BY trainerOnJobTime")
    public List<Map<String, Object>> getTrainersListOrderByOnJobTime();

    /**
     * 获取教练列表
     * 按照年龄排列
     */
    @Select("SELECT * FROM trainersinfo ORDER BY trainerAge")
    public List<Map<String, Object>> getTrainersListOrderByAge();

    /**
     * 获取教练列表
     * 按照工作经验排序
     */
    @Select("SELECT * FROM trainersinfo ORDER BY trainerExperience DESC")
    public List<Map<String, Object>> getTrainersListOrderByExperience();

    /**
     * 寻找单一性别的教练
     */
    @Select("SELECT * FROM trainersinfo WHERE trainerSex = #{trainerSex}")
    public List<Map<String, Object>> getTrainersListBySex(@Param("trainerSex") String trainerSex);

    /**
     * 更改教练头像
     */
    @Update("UPDATE trainersinfo SET trainerImage = #{trainer.trainerImage} WHERE trainerId = #{trainer.trainerId}")
    public boolean updateTrainerImage(@Param("trainer") Map<String, String> trainer);
}
